<?php 
$formAttrib = array('id' => 'addroom', 'class' => 'admin-form custom');	
foreach($level_data as $lvl_data){
		$level_desc = $lvl_data->level_desc;
		$level_id	= $lvl_data->level_id;
}

?>
<?if(isset($system_message))echo $system_message;?>
<div>
	<div class="panel">
		<p><b>Existing Fees</b></p>
	</div>
	<div class="row">
		<div class="large-12 columns">
		<div class="large-6 columns">
		<div class="table-responsive">
			<table class="table table-striped table-bordered">
			<tbody>
			<tr><td colspan="3" style="text-align:center; font-weight:bold;">New Student</td></tr>
			<?if(!empty($all_fees_assigned)):?>
			<?php $total = 0.00; ?>
			<?foreach($all_fees_assigned as $v):?>
				<?php $total += $v['fee_rate']; ?>
				<tr>
					<td><?=ucwords($v['fee_name']);?></td>
					<td style="text-align:right"><?=money($v['fee_rate']);?></td>
					<td>
						<?php
							if(isset($v['is_misc_fee']) OR isset($v['is_tuition_fee']) OR isset($v['is_cca_fee']))
							{
								if($v['is_misc_fee'])
								{
									echo ' Other School Fee';
								}elseif($v['is_tuition_fee']){
									echo ' Tuition Fee';
								}elseif($v['is_cca_fee']){
									echo ' Matriculation Fee';
								}
							}else{
								echo ' Miscellaneous';
							}
						?>
					</td>
				</tr>
			<?endforeach;?>
				<tr>
					<td style="font-weight:bold;">Total</td>
					<td style="font-weight:bold; text-align:right;"><?=money($total);?></td>
					<td>&nbsp;</td>
				</tr>
			<?else:?>
				<tr>
				<td colspan="3">
					No Fees has been assigned for this Grade Level.
				</td>
				</tr>
			<?endif;?>
			</tbody>
			</table>
		</div>
		</div>
		<div class="large-6 columns">
		<div class="table-responsive">
			<table class="table table-striped table-bordered">
			<tbody>
			<tr><td colspan="3" style="text-align:center; font-weight:bold;">Old Student</td></tr>
			<?if(!empty($old_fees_assigned)):?>
			<?php $total = 0.00; ?>
			<?foreach($old_fees_assigned as $v):?>
				<?php $total += $v['fee_rate']; ?>
				<tr>
					<td><?=ucwords($v['fee_name']);?></td>
					<td style="text-align:right"><?=money($v['fee_rate']);?></td>
					<td>
						<?php
							if(isset($v['is_misc_fee']) OR isset($v['is_tuition_fee']) OR isset($v['is_cca_fee']))
							{
								if($v['is_misc_fee'])
								{
									echo ' Other School Fee';
								}elseif($v['is_tuition_fee']){
									echo ' Tuition Fee';
								}elseif($v['is_cca_fee']){
									echo ' Matriculation Fee';
								}
							}else{
								echo ' Miscellaneous';
							}
						?>
					</td>
				</tr>
			<?endforeach;?>
				<tr>
					<td style="font-weight:bold;">Total</td>
					<td style="font-weight:bold; text-align:right;"><?=money($total);?></td>
					<td>&nbsp;</td>
				</tr>
			<?else:?>
				<tr>
				<td colspan="3">
					No Fees has been assigned for this Grade Level.
				</td>
				</tr>
			<?endif;?>
			</tbody>
			</table>
		</div>
		</div>
		</div>
	</div>
</div>

<div class="table-responsive">
	<div class="panel">
		<p><b>Set Grade Level Fees for <?=$level_desc;?></b></p>
	</div>
	<?php echo form_open('admin/set_grade_level_fees',$formAttrib);?>
	<table class="table table-striped table-bordered">
		<thead class="tabular-head">
			<tr>
				<th>Fees</th>
				<th>Fee Description</th>
				<th>Fee Rates</th>
			</tr>
			</thead>
		<tbody class="tabular">
			<thead>
				<tr class="info">
					<th colspan="3" class="text-center">Selected Fees</th>
				</tr>
			</thead>
			<?if($selected_fees !== FALSE):?>
				<?foreach($selected_fees as $s_fees):?>
					<tr>
						<td>
							<input type="checkbox" name="fee[][lf_fee_id]" value="<?=$s_fees['id'];?>"checked>&nbsp;&nbsp;<?=$s_fees['name'];?>
						</td>
						<td><?=$s_fees['desc'];?></td>
						<td style="text-align:right;"><?=money($s_fees['rate']);?></td>
					</tr>
					<?$s_rate[] = $s_fees['rate']?> 
				<?endforeach;?>
				<tr><td>Total</td><td></td><td style="text-align:right;"><?=money(array_sum($s_rate));?></td></tr>
			
			<?else:?>
				<tr class="error">
					<td colspan="3">No Fees assigned for this level.</td>
				</tr>
			<?endif;?>
		</tbody>
		
		<tbody>
			<thead>
				<tr class="info">
					<td colspan="3" class="text-center">Available Fees</td>
				</tr>
			</thead>
			<?if(!empty($available_fees)):?>
				<?foreach($available_fees as $fees):?>
				<tr>
					<td>
						<input type="checkbox" name="fee[][lf_fee_id]"value="<?=$fees['id'];?>">&nbsp;&nbsp;<?=$fees['name'];?>
					</td>
					<td><?=$fees['desc'];?></td>
					<td style="text-align:right;"><?=money($fees['rate']);?></td>
				</tr>
				<?$rate[] = $fees['rate']?> 
			<?endforeach;?>
			<tr><td>Total</td><td></td><td style="text-align:right;"><?=money(array_sum($rate));?></td></tr>
		<?else:?>
			<tr class="success">
				<td colspan="3">All Fees are already assigned for this Grade Level.</td>
			</tr>
		<?endif;?>
		</tbody>	
	</table>
	<input type="hidden" name="lf_level_id" value="<?=$level_id;?>">
	<input type="submit" class="btn btn-primary" name="set_grade_level_fees" value="Update Level Fees">
	<a href="<?php echo site_url('admin/grade_level_fees'); ?>" class="btn btn-default">Back</a>
	<?echo form_close();?>
	
</div>

